package it.unisa.indianamas.idm;


import java.util.ArrayList;
import java.util.StringTokenizer;

import com.mathworks.toolbox.javabuilder.*;

import vastidm.*;

public class IDM {
	private String query;
	private String[] dataset;
	private int categories;
	private int size;
	private int localContext;
	private int warpRange;
	private int threshold;
	
	
	
	
	
	public IDM(String query, String[] dataset, int categories, int size,
			int localContext, int warpRange, int threshold) {
		super();
		this.query = query;
		this.dataset = dataset;
		this.categories = categories;
		this.size = size;
		this.localContext = localContext;
		this.warpRange = warpRange;
		this.threshold = threshold;
	}
	
	public ArrayList<IDMResult> run() throws Exception{
		vastidm.Class1 x = null;
		Object[] result = null;
		ArrayList<IDMResult> results = new ArrayList<IDMResult>();
	
			x = new vastidm.Class1();
			Object[] list = new Object[8];
			list[0] = query;
			list[1] = dataset;
			list[2] = false;
			list[3] = categories;
			list[4] = size;
			list[5] = localContext;
			list[6] = warpRange;
			list[7] = threshold;
			
			result = x.TestIDMDistanceOld(1, list);
			MWCellArray mwCellArray = (MWCellArray) result[0];
			StringTokenizer st2 = new StringTokenizer(mwCellArray.toString(), "\n");
			
			while (st2.hasMoreElements()) {
				StringTokenizer st = new StringTokenizer((String) st2.nextElement(),"'[]");

				st.nextElement();
				String query = (String) st.nextElement();
				st.nextElement();
				String compare = (String) st.nextElement();
				st.nextElement();
				double distance = Double.parseDouble((String)st.nextElement());
				IDMResult resultComparison = new IDMResult(query,compare, distance);
				results.add(resultComparison);
			}
		return results;
	}
	
	
	public String getQuery() {
		return query;
	}
	public void setQuery(String query) {
		this.query = query;
	}
	public String[] getDataset() {
		return dataset;
	}
	public void setDataset(String[] dataset) {
		this.dataset = dataset;
	}
	public int getCategories() {
		return categories;
	}
	public void setCategories(int categories) {
		this.categories = categories;
	}
	public int getSize() {
		return size;
	}
	public void setSize(int size) {
		this.size = size;
	}
	public int getLocalContext() {
		return localContext;
	}
	public void setLocalContext(int localContext) {
		this.localContext = localContext;
	}
	public int getWarpRange() {
		return warpRange;
	}
	public void setWarpRange(int warpRange) {
		this.warpRange = warpRange;
	}
	public int getThreshold() {
		return threshold;
	}
	public void setThreshold(int threshold) {
		this.threshold = threshold;
	}
	
	
	
}
